package com.lanju.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.lanju.entity.Introduce;
import com.lanju.entity.Message;

@Repository
public class IntroduceDao {

	
	 private static final Log log = LogFactory.getLog(IntroduceDao.class);
	    @PersistenceContext(unitName = "financialmarketingUnit")
		private EntityManager entityManager;
	    
	    
	public void addIntroduce(Introduce i){
		try {
			entityManager.persist(i);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Introduce getIntroduceDetail(Integer id) {
		try {
			Introduce i=entityManager.find(Introduce.class, id);
			return i;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public void saveMessage(Message m) {
		try {
			entityManager.persist(m);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public List<Message> getMessageList(Integer type){
		List<Message> list = null;
		try {
			StringBuffer sql=new StringBuffer();
			sql.append("from Message where type="+type +" and status =1 order by createTime desc");
			Query query=entityManager.createQuery(sql.toString());
			list = query.getResultList();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
}
